package class202204._26_30._29;


import javax.jws.soap.SOAPBinding;
import java.util.Arrays;
import java.util.Locale;

interface A{
    public static final String name = "dace";
}

public class TestDemo {

    public static void main(String[] args) {
        char[] ch = new char[]{'a','b','c'};
        String str = new String(ch);
        str.intern();
        String str2 = "abc";
        System.out.println(str == str2);
    }

    /**
     * 只要是new的  就一定有新对象产生的
     * @param args
     */

    public static void main16(String[] args) {
        String str1 = "hello";
        String ret = "he" + "llo";
        System.out.println(ret == str1); //常量在编译的候时 这里就是hello 了
        String str2 = "he";
        String str3 = "llo";
        String str4 = str2 + str3;  // str2 和str4 事变量，在编译的时候还不知道里面是谁
        System.out.println(str1 == str4);
        String s = "";
        String s1 = new String();
        System.out.println(s1.length());
        System.out.println(s.length());
    }

    public static void main15(String[] args) {
        String str1 = "hello";
        String str2 = "hello";
        String str3 = new String("hello");
        System.out.println(str1 == str2);
        System.out.println(str1 == str3);
    }

    /**
     * 左右去空格
     * @param args
     */
    public static void main14(String[] args) {
        String str = "     abc    asdf     ";
        String s = str.trim();
        System.out.println(s);
        System.out.println(str);
    }

    /**
     * 截取   范围一定要合法
     * @param args
     */
    public static void main13(String[] args) {
        String str = "ababcabcd";
        String ret = str.substring(2,7);
        System.out.println(ret);
    }

    /**
     * 二次分割
     * @param args
     */
    public static void main12(String[] args) {
        String str = "name=zhangsan&age=18";
        String[] strings = str.split("&");
        for (String s:strings) {
            String[] s1 = s.split("=");
            for (String x:s1) {
                System.out.println(x);
            }
        }
    }

    public static void main11(String[] args) {
        String str = "JAVA104 BIT&666";
        String[] strings = str.split(" |&");
        for (String s:strings) {
            System.out.println(s);
        }
    }

    public static void main10(String[] args) {
        String str = "abc def fh";
        String[] strings = str.split(" ");
        for (String s:strings) {
            System.out.println(s);
        }
    }

    public static void main9(String[] args) {
        String str = "ababcabcdabcde";
        //String  str2 = str.replace("ab","mn");//单引号正引一个字符  换双引号
        //String str2 = str.replaceAll("ab","mn");
        String str2 = str.replaceFirst("ab","mn");
        System.out.println(str);
        System.out.println(str2);
    }

    public static void main8(String[] args) {
        String s = "hello";
        char[] chars = s.toCharArray();
        System.out.println(Arrays.toString(chars));
//格式化输出
        String s1 = String.format("%d-%d-%d", 2019, 9,14);
        System.out.println(s1);
    }

    public static void main7(String[] args) {
        String s = "hello";
        String s2 = s.toUpperCase();
        System.out.println(s2);
        String s1 = "HELLO";
        String s3 = s.toLowerCase();
        System.out.println(s3);
    }

    public static void main6(String[] args) {
        int a = 10;
        String str = String.valueOf(a);//变为字符串“10”
        System.out.println(str);
    }
    public static void main5(String[] args) {
        String str = "ababcabcd";
        //System.out.println(str.lastIndexOf('a'));
        int last = str.lastIndexOf('a');
        System.out.println(last);
    }

    public static void main4(String[] args) {

        String str = "hello";
        //char ch = str.charAt(0);//字符串查找,输入要查找的下标，用char类型接收，注意不能超出范围
        int index = str.indexOf('h');//字符串查找,输入要查找的字符  返回下标   如果返回负数  说明没有这个字符 如果有相同字符  只找第一个
        System.out.println(index);
    }

    public static void main3(String[] args) {
        /**
         * 这里String重写了toString  因为拿到的()s1不是地址
         */
        //只要你new你就会开辟新的空间
        String s1 = new String("hello");
        String s2 = new String("Hello");
        System.out.println(s1);
        System.out.println(s1.equals(s2));
        System.out.println(s1.equalsIgnoreCase(s2)); //忽视大小写比较
      /*  System.out.println(s1 == s2);//地址
        //Object
        System.out.println(s1.equals(s2));//内容的比较
        System.out.println(s1.compareTo(s2));//String   大小的排序 h-h*/
    }

    public static void main2(String[] args) {
        String s1 = new String("hello");
        String s2 = new String("world");
        String s3 = s1;
        System.out.println("=========");
        System.out.println(s1.length());
        System.out.println(s2.length());
        System.out.println(s3.length());
    }


    public static void main1(String[] args) {
        String str = "hello";
        String str2 = new String("world");
        System.out.println(str2);
        char[] chars = {'a','b','c'};
        String str3 = new String(chars);
    }
}
